//
//  ST_MaidSelectWayViewController.swift
//  maid
//
//  Created by DC on 2022/3/15.
//

import UIKit

class ST_MaidSelectWayViewController: UIViewController {

    var choose_block: ((Int) -> ())?
    
    fileprivate var way = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()

        make_u_i()
    }
    
    fileprivate func make_u_i() {
        view.addSubviews([close_button, root_view])
        root_view.addSubviews([titleLabel, cancel_button, zImageView, zLabel, z_select_image_view, zButton, wImageView, wLabel, w_select_image_view, wButton, ok_button])
        
        close_button.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        root_view.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.size.equalTo(CGSize(width: 300, height: 325))
        }
        
        titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(42)
            make.height.equalTo(28)
        }
        
        cancel_button.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-13)
            make.top.equalToSuperview().offset(9)
            make.size.equalTo(CGSize(width: 43, height: 43))
        }
        
        zImageView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(29)
            make.top.equalTo(titleLabel.snp.bottom).offset(26)
            make.size.equalTo(CGSize(width: 40, height: 40))
        }
        
        zLabel.snp.makeConstraints { make in
            make.centerY.equalTo(zImageView)
            make.left.equalTo(zImageView.snp.right).offset(17)
        }
        
        z_select_image_view.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-37)
            make.centerY.equalTo(zImageView)
            make.size.equalTo(CGSize(width: 21, height: 21))
        }
        
        zButton.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.centerY.equalTo(zImageView)
            make.height.equalTo(50)
        }
        
        wImageView.snp.makeConstraints { make in
            make.left.equalTo(zImageView)
            make.top.equalTo(zImageView.snp.bottom).offset(36)
            make.size.equalTo(zImageView)
        }
        
        wLabel.snp.makeConstraints { make in
            make.centerY.equalTo(wImageView)
            make.left.equalTo(zLabel)
        }
        
        w_select_image_view.snp.makeConstraints { make in
            make.centerY.equalTo(wImageView)
            make.right.equalToSuperview().offset(-37)
            make.size.equalTo(CGSize(width: 21, height: 21))
        }
        
        wButton.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.centerY.equalTo(wImageView)
            make.height.equalTo(50)
        }
        
        ok_button.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-26)
            make.size.equalTo(CGSize(width: 200, height: 44))
        }
    }
    
    fileprivate lazy var close_button: UIButton = {
        let v = UIButton()
        v.backgroundColor = .clear
        v.addTarget(self, action: #selector(close_handle), for: .touchUpInside)
        return v
    }()
    
    fileprivate lazy var root_view: UIView = {
        let v = UIView()
        v.backgroundColor = .white
        v.cornerRadius = 20
        return v
    }()
    
    fileprivate lazy var titleLabel: UILabel = {
        let v = UILabel()
        v.text = "支付方式"
        v.textColor = UIColor(hexString: "#333333")
        v.font = .systemFont(ofSize: 20, weight: .semibold)
        return v
    }()
    
    fileprivate lazy var cancel_button: UIButton = {
        let v = UIButton()
        v.setImageForAllStates(ST_ImageUtils.imageName("dismal_sandwich_tapeworm_mess") ?? UIImage())
        v.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
        v.addTarget(self, action: #selector(close_handle), for: .touchUpInside)
        return v
    }()
    
    fileprivate lazy var zImageView: UIImageView = {
        let v = UIImageView()
        v.image = ST_ImageUtils.imageName("sceptical_mound_motet_uninterested")
        return v
    }()
    
    fileprivate lazy var zLabel: UILabel = {
        let v = UILabel()
        v.text = "支付宝"
        v.textColor = UIColor(hexString: "#333333")
        v.font = .systemFont(ofSize: 18, weight: .regular)
        return v
    }()
    
    fileprivate lazy var z_select_image_view: UIImageView = {
        let v = UIImageView()
        v.image = ST_ImageUtils.imageName("scuba_notification_xuanze")
        return v
    }()
    
    fileprivate lazy var zButton: UIButton = {
        let v = UIButton()
        v.backgroundColor = .clear
        v.addTarget(self, action: #selector(z_handle), for: .touchUpInside)
        return v
    }()
    
    fileprivate lazy var wImageView: UIImageView = {
        let v = UIImageView()
        v.image = ST_ImageUtils.imageName("marshmallow_appointment_quarantine_rear")
        return v
    }()
    
    fileprivate lazy var wLabel: UILabel = {
        let v = UILabel()
        v.text = "微信"
        v.textColor = UIColor(hexString: "#333333")
        v.font = .systemFont(ofSize: 18, weight: .regular)
        return v
    }()
    
    fileprivate lazy var w_select_image_view: UIImageView = {
        let v = UIImageView()
        v.image = ST_ImageUtils.imageName("disparity_punt_weixuanze")
        return v
    }()
    
    fileprivate lazy var wButton: UIButton = {
        let v = UIButton()
        v.backgroundColor = .clear
        v.addTarget(self, action: #selector(w_handle), for: .touchUpInside)
        return v
    }()
    
    fileprivate lazy var ok_button: UIButton = {
        let v = UIButton()
        v.backgroundColor = UIColor(hexString: "#FEC207")
        v.cornerRadius = 22
        v.setTitleForAllStates("确认支付")
        v.setTitleColorForAllStates(UIColor.white)
        v.titleLabel?.font = .systemFont(ofSize: 18, weight: .semibold)
        v.addTarget(self, action: #selector(ok_handle), for: .touchUpInside)
        return v
    }()
}

extension ST_MaidSelectWayViewController {
    
    @objc fileprivate func close_handle() {
        self.goback_previous_controller()
    }
    
    @objc fileprivate func z_handle() {
        way = 0
        z_select_image_view.image = ST_ImageUtils.imageName("scuba_notification_xuanze")
        w_select_image_view.image = ST_ImageUtils.imageName("disparity_punt_weixuanze")
    }
     
    @objc fileprivate func w_handle() {
        way = 1
        z_select_image_view.image = ST_ImageUtils.imageName("disparity_punt_weixuanze")
        w_select_image_view.image = ST_ImageUtils.imageName("scuba_notification_xuanze")
    }
    
    @objc fileprivate func ok_handle() {
        self.goback_previous_controller(animated: true) {
            self.choose_block?(self.way)
        }
    }

}
